package com.ymatou.iapi.livebuyer.testcase;

import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.ymatou.iapi.livebuyer.parameter.QueryLiveMessageBean;
import com.ymatou.iapi.livebuyer.service.QueryLiveMessageCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.YmtLoggingWapper;
/**
*查询回播留言
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryLiveMessage{
	private static QueryLiveMessageBean querylivemessageBean;
	private static QueryLiveMessageCall querylivemessageCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询回播留言");
	}

	@Before
	public void caseUp() {
		querylivemessageBean=new QueryLiveMessageBean();
		querylivemessageCall=new QueryLiveMessageCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querylivemessageCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryLiveMessage_001() {
		Logger.start(true,"查询回播留言成功");
		try {
			YmtLoggingWapper ylw=new YmtLoggingWapper();
			Integer liveid=Integer.valueOf(ylw.selectLiveMessage(null, 1).get(0).get("LiveId").toString());
			querylivemessageBean.setLiveId(liveid);
			querylivemessageCall.setData(querylivemessageBean);
			querylivemessageCall.callService();			
			Logger.verifyEquals("200", querylivemessageCall.getString("code"), "验证code");
			List<Map> list = new YmtLoggingWapper().selectLiveMessage(liveid, 1);
			JsonArray rmsglist = querylivemessageCall.getJsonObject().get("data").getAsJsonObject().get("messageList").getAsJsonArray();
			Logger.verifyEquals(list.size(),rmsglist.size(), "验证消息条数");
			ListIterator<Map> mlist = list.listIterator();
			rmsglist.forEach(msg->{
				Map tmsg=mlist.next();
				Logger.verifyEquals(msg.getAsJsonObject().get("userId").getAsString(),tmsg.get("UserId").toString(),"验证userId");
				Logger.verifyEquals(msg.getAsJsonObject().get("nickName").getAsString(),tmsg.get("NickName").toString(),"验证nickName");
				Logger.verifyEquals(msg.getAsJsonObject().get("msgTime").getAsString(),tmsg.get("MsgTime").toString().substring(0,19),"验证msgTime");
				Logger.verifyEquals(msg.getAsJsonObject().get("msgContent").getAsString(),tmsg.get("MsgContent").toString(),"验证msgContent");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QueryLiveMessage_002() {
		Logger.start(true,"不输入liveId失败");
		try {
			querylivemessageCall.setData(querylivemessageBean);
			querylivemessageCall.callService();			
			Logger.verifyEquals("100", querylivemessageCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}